﻿@{
    ResLink.AddJs("~/res/jquery/js/jquery-ui-1.10.3.custom.min.js");
}

<div id="강의대화상자" class="modal hide" tabindex="-1" role="dialog" >
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h1>강의 검색</h1>
    </div>

    <div class="modal-body">
        <div class="form-horizontal">
            <span>강의명:</span>
            <input id="강의대화상자_검색패턴" type="text" />
            <button class="btn" onclick='강의대화상자_검색()'>검색</button>
        </div>
        <div id="강의대화상자_검색결과_박스">
            <div id="강의대화상자_검색결과">
            </div>
        </div>            
    </div>

    <div class="modal-footer">
        <a class="btn" data-dismiss="modal">취소</a>
        <a class="btn btn-primary" data-dismiss="modal" onclick="강의대화상자_확인()">확인</a>
  </div>
</div>

<script type="text/javascript">
    function 강의검색() {
        $("#강의대화상자").modal('show');
        $("#강의대화상자 input[type=text]").focus();
    }

    function 강의대화상자_검색() {
        $("#강의대화상자_검색결과").load("/Application/SearchLecture", { pattern: $("#강의대화상자_검색패턴").val() }, OnAjaxLoadComplete).selectable();
    }

    function 강의대화상자_확인() {
        var item = $("#강의대화상자_검색결과 .ui-selected");
        if (item.length == 0) { alert("항목을 선택하세요"); return; }

        var ID = item.attr("data-key");
        var 학기 = item.find("span:nth-child(1)").html();
        var 강의명 = item.find("span:nth-child(2)").html();

        var s = "<tr><td><input type='checkbox' /></td><td>{1}</td><td>{2} <input type='hidden' name='강의ID' value='{0}' /></td></tr>";
        s = s.replace("{0}", ID).replace("{1}", 학기).replace("{2}", 강의명);
        $('table.table > tbody:last').append(s);
    }
</script>